<template>
  <Layout>
    <div style="min-height: 600px">
      <el-card shadow="never" style="min-height: 400px">
        <div slot="header">
          <el-row>
            <el-col :span="12">
              <span>{{ $page.blog.title }}</span>
            </el-col>
            <el-col :span="12">
              <div style="text-align: right">
                <el-button
                  @click="$share()"
                  style="padding: 3px 0"
                  type="text"
                  icon="el-icon-share"
                  >分享</el-button
                >

                <el-button
                  style="padding: 3px 0"
                  type="text"
                  icon="el-icon-more-outline"
                  @click="more"
                  >更多博客</el-button
                >
              </div>
            </el-col>
          </el-row>
        </div>
        <div style="font-size: 0.9rem; line-height: 1.5; color: #606c71">
          发布 {{ $page.blog.createTime }} <br />
          更新 {{ $page.blog.updateTime }}
        </div>
        <div
          style="
            font-size: 1.1rem;
            line-height: 1.5;
            color: #303133;
            border-bottom: 1px solid #e4e7ed;
            padding: 5px 0px 5px 0px;
          "
        >
          <pre style="font-family: '微软雅黑'">{{
            $page.blog.description
          }}</pre>
        </div>
        <div
          v-loading="loading"
          v-html="content"
          class="markdown-body"
          style="padding-top: 20px"
        ></div>
      </el-card>
    </div>
  </Layout>
</template>

<page-query>
query ($id: ID!) {
  blog: blog(id: $id) {
    id
    title
    url {
        filename
        type
        raw_url
        size
        language
    }
    description
    createTime
    updateTime
    hide
    }
  
}
</page-query>

<script>
import { mapGetters } from "vuex";
import GistApi from "../../src/api/gist";
export default {
  data() {
    return {
      content: "",
      loading: false
    }
  },
  async mounted() {
    this.loading = true
    let id = this.$page.blog.id
    let response = await GistApi.single(this.$page.blog.id);
    let result = response.data
    for (let key in result.files) {
      let mavonEditor =require('mavon-editor')
        this.content = mavonEditor.markdownIt.render(result.files[key]['content'])
        break
    }
    this.loading = false
  },
  methods: {
    more() {
      this.$router.push("/user/blog");
    },
  },
};
</script>